<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="../static/css/bootstrap.css" />
    <!--需要在Javascript之前引入JQuer-->
    <script type="text/javascript" src="../static/js/jquery-1.11.0.js"></script>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script type="text/javascript" src="../static/js/bootstrap.js"></script>
    <!--针对移动设备的样式，为了确保适当的绘制和触屏缩放-->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!--jquery.cookie.js-->
    <script src="../static/js/jquery.cookie.js"></script>
    <!--翻页-->
    <link rel="stylesheet" href="../static/css/pagination.css">
    <script src="../static/js/pagination.js"></script>
</head>
<body>
<div class="container-fluid" style="padding: 0 200px;">
    <div class="row-fluid jumbotron">
        <div class="span12">

            <div class="row-fluid">
                <div class="span12">
                    <span style="float: right;">
                         <a href="/content/detail">
                             <span class="glyphicon glyphicon-home"> 首页</span>
                         </a>
                    </span>
                </div>
            </div>
            <div class="row-fluid">
                <div class="span12">
                    <div class="row-fluid">
                        <div class="span12">
                            <div class="page-header">
                                <a id="modal-968973" href="/contentlist/page" role="button" class="btn" data-toggle="modal">
                                <h1>
                                    文章列表
                                </h1>
                                </a>
                            </div>
                        </div>
                    </div>
                    <div class="row-fluid">
                        <div class="span12">
                            <div class="" style="float: right;">
                                <input maxlength="10" size="35" class="input-medium search-query" type="text" placeholder="输入相关文章信息......"/>
                                <button class="btn" id="oneId" onclick="FuzzyQspage(1)">查找</button>
                            </div>
                            <ul class="nav nav-tabs">
                                <li class="active">
                                    <a href="#home" data-toggle="tab">文章管理</a>
                                </li>
                                <li>
                                    <a href="#ios" onclick="CommentData()" data-toggle="tab">评论管理</a>
                                </li>
                                <li class="disabled">
                                    <a href="#" id="count">总数<span class="badge pull-right">0</span></a>
                                </li>
                            </ul>
                            <div id="myTabContent" class="tab-content">
                                <div class="tab-pane fade in active" id="home">
                                    <table class="table table-hover  table-striped" id="msgList">
                                        <thead>
                                        <tr>
                                            <th>
                                                ID
                                            </th>
                                            <th>
                                                标题
                                            </th>
                                            <th>
                                                内容
                                            </th>
                                            <th>
                                                作者
                                            </th>
                                            <th>
                                                备注
                                            </th>
                                            <th>
                                                发表时间
                                            </th>
                                            <th>
                                                检查
                                            </th>
                                            <th>
                                                删除
                                            </th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        </tbody>

                                    </table>
                                    <div id="pages"></div>
                                </div>
                                <div class="tab-pane fade" id="ios">
                                    <table class="table table-hover table-striped" id="commentList">
                                        <thead>
                                        <tr>
                                            <th>
                                                文章ID
                                            </th>
                                            <th>
                                                评论内容
                                            </th>
                                            <th>
                                                评论时间
                                            </th>
                                            <th>
                                                评论者
                                            </th>
                                            <th>
                                                通过
                                            </th>
                                            <th>
                                                删除
                                            </th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        </tbody>
                                    </table>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script >
    //模糊查询用户
    function  FuzzyQspage(currentPage) {
        var val = $(".search-query").val();
        if (val.length != 0) {
            $("#msgList tbody").empty();
            pageSize = 10;
            offset = (currentPage - 1) * pageSize
            offset = offset < 1 ? 0 : offset;
            var messageListUrl = "/content/fuzzy?offset=" + offset + "&limit=" + pageSize+ "&value=" + val
            $.post(messageListUrl, function (RspData, status) {
                console.log(RspData)
                console.log(status)
                if (RspData.msgcount > 0) {
                    totalPages = Math.ceil(RspData.msgcount / pageSize)
                    console.log("status", totalPages)
                    new Pagination({
                        element: '#pages',
                        type: 1,
                        pageIndex: currentPage,
                        pageSize: 10,
                        total: RspData.msgcount,
                        jumper: true,
                        singlePageHide: false,
                        prevText: '上一页',
                        nextText: '下一页',
                        disabled: true,
                        currentChange: function (index) {
                            // console.log(index);
                            FuzzyQspage(index)
                        }
                    });
                    //显示总数量
                    $("#count span").html(RspData.msgcount);
                    console.log("status")
                    var trhtml =""
                    for ( var i in RspData.data) {
                        // console.log(byId2)
                        //截取正文字符串
                        var text = RspData.data[i].Text;
                        if (text.length > 80){
                            text = text.slice(0,80);
                        }
                        var checkStyleOK = "";
                        var checkStyleNO = "style='display: none'";
                        if (RspData.data[i].Status == "0"){
                            checkStyleOK = "style='display: none'";
                            checkStyleNO = "";
                        }
                        trhtml += "<tr id='trone'>" +
                            "<td>"+RspData.data[i].M_id+"</td>" +
                            "<td>"+RspData.data[i].Hdline+"</td>" +
                            "<td>"+text+"...</td>" +
                            "<td>"+RspData.data[i].Name+"</td>" +
                            "<td>"+RspData.data[i].Remark+"</td>" +
                            "<td>"+RspData.data[i].Cr_time+"</td>" +
                            "<td>"+
                            "<a "+checkStyleOK+">" +
                            "<span class=\"glyphicon glyphicon-ok\" style=\"color: rgb(74, 167, 53);\">"+
                            "</span>"+
                            "</a>"+
                            "<a "+checkStyleNO+">" +
                            "<span class=\"glyphicon glyphicon-remove\" style=\"color: rgb(191, 34, 23);\"> "+
                            "</span>"+
                            "</a>"+
                            "<a class=\"btn\" href=\"#\" onclick='Sort("+RspData.data[i].Status+","+RspData.data[i].M_id+")'>" +
                            "<span class=\"glyphicon glyphicon-sort\" style=\"color: rgb(65, 93, 226);\">"+
                            "</span>"+
                            "</a>"+
                            "</td>" +
                            "<td>"+
                            "<a class=\"btn\" href=\"#\" onclick='Trash("+RspData.data[i].M_id+")'>" +
                            "<span class=\"glyphicon glyphicon-trash\">"+
                            "</span>"+
                            "</a>"+
                            "</td>" +
                            "</tr>";
                    }
                    $("#msgList tbody").html(trhtml);
                }else {
                    alert("你输入的信息，我们查询不到任何东西哦！");
                }
            });
        }
    }
    //获取页面数据
    pageAutoLoadData(1);
    function  pageAutoLoadData(currentPage) {
        $("#msgList tbody").empty();
        pageSize =10;
        offset = (currentPage-1)*pageSize
        offset = offset<1 ? 0 :offset;
        var messageListUrl ="/content/getlist?offset=" + offset + "&limit=" + pageSize+"&stu=" + 0
        $.get(messageListUrl, function(RspData, status) {
            console.log(RspData)
            if (RspData.msgcount>0) {
                totalPages = Math.ceil( RspData.msgcount/pageSize)
                console.log("status",totalPages)
                new Pagination({
                    element: '#pages',
                    type: 1,
                    pageIndex: currentPage,
                    pageSize: 10,
                    total: RspData.msgcount,
                    jumper: true,
                    singlePageHide: false,
                    prevText: '上一页',
                    nextText: '下一页',
                    disabled: true,
                    currentChange: function(index) {
                        // console.log(index);
                        pageAutoLoadData(index)
                    }
                });

            }
            //显示总数量
            $("#count span").html(RspData.msgcount);
            var trhtml =""
            for ( var i in RspData.data) {
                // console.log(byId2)
                //截取正文字符串
                var text = RspData.data[i].Text;
                if (text.length > 50){
                    text = text.slice(0,50);
                }
                var checkStyleOK = "";
                var checkStyleNO = "style='display: none'";
                if (RspData.data[i].Status == "0"){
                     checkStyleOK = "style='display: none'";
                     checkStyleNO = "";
                }
                trhtml += "<tr id='trone'>" +
                    "<td>"+RspData.data[i].M_id+"</td>" +
                    "<td>"+RspData.data[i].Hdline+"</td>" +
                    "<td>"+text+"...</td>" +
                    "<td>"+RspData.data[i].Name+"</td>" +
                    "<td>"+RspData.data[i].Remark+"</td>" +
                    "<td>"+RspData.data[i].Cr_time+"</td>" +
                    "<td>"+
                    "<a "+checkStyleOK+">" +
                    "<span class=\"glyphicon glyphicon-ok\" style=\"color: rgb(74, 167, 53);\">"+
                    "</span>"+
                    "</a>"+
                    "<a "+checkStyleNO+">" +
                    "<span class=\"glyphicon glyphicon-remove\" style=\"color: rgb(191, 34, 23);\"> "+
                    "</span>"+
                    "</a>"+
                    "<a class=\"btn\" href=\"#\" onclick='Sort("+RspData.data[i].Status+","+RspData.data[i].M_id+")'>" +
                    "<span class=\"glyphicon glyphicon-sort\" style=\"color: rgb(65, 93, 226);\">"+
                    "</span>"+
                    "</a>"+
                    "</td>" +
                    "<td>"+
                    "<a class=\"btn\" href=\"#\" onclick='Trash("+RspData.data[i].M_id+")'>" +
                    "<span class=\"glyphicon glyphicon-trash\">"+
                    "</span>"+
                    "</a>"+
                    "</td>" +
                    "</tr>";
            }
            $("#msgList tbody").html(trhtml);
        });
        //打开修改框
    }
    //删除文章信息
    function Trash(id) {
        var delUrl ="/content/del?id="+id;
        $.post(delUrl,function () {
            alert("删除成功！");
            window.location.reload();
        })
    }
    //修改状态
    function Sort(num,id) {
        var EditUrl ="";
        if (num == "1"){
            num = 0;
            EditUrl ="/content/status/edit?num="+num+"&id="+id;
        }else {
            num = 1;
            EditUrl ="/content/status/edit?num="+num+"&id="+id;
        }
        $.post(EditUrl,function () {
            alert("修改成功！");
            window.location.reload();
        })
    }
    //获取评论数据

    function  CommentData() {
        $("#pages").remove();
        $("#commentList tbody").empty();
        var messageListUrl ="/message/list/uncheck"
        $.get(messageListUrl, function(Data) {
            console.log(Data)
            if (Data.List.length>0) {
                console.log(Data.List.length)
                var trhtml =""
                for ( var i in Data.List) {
                    console.log(Data.List)
                    trhtml += "<tr id='trone'>" +
                        "<td>"+Data.List[i].Message_id+"</td>" +
                        "<td>"+Data.List[i].Content+"</td>" +
                        "<td>"+Data.List[i].Send_time+"</td>" +
                        "<td>"+Data.List[i].Send_time+"</td>" +
                        "<td>"+
                        "<a class=\"btn\" href=\"#\" onclick='EditCheck("+Data.List[i].Id+")'>" +
                        "<span class=\"glyphicon glyphicon-share-alt\" style=\"color: rgb(44, 140, 60);\">"+
                        "</span>"+
                        "</a>"+
                        "</td>" +
                        "<td>"+
                        "<a class=\"btn\" href=\"#\" onclick='DelComment("+Data.List[i].Id+")'>" +
                        "<span class=\"glyphicon glyphicon-trash\">"+
                        "</span>"+
                        "</a>"+
                        "</td>" +
                        "</tr>";
                }
                $("#commentList tbody").html(trhtml);
            }
        });
    }
    //删除评论
    function DelComment(id) {
        var delUrl ="/message/del?c_id="+id;
        $.post(delUrl,function () {
            alert("删除成功！");
            // window.location.reload();
            CommentData();
        })
    }
    //通过评论
    function EditCheck(id) {
        var Url ="/message/check?id="+id;
        $.post(Url,function () {
            alert("成功！");
            // window.location.reload();
            CommentData();
        })
    }
</script>
</html>